<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教务系统</title>
</head>
<body>
<div>
    <h3>注册</h3>
    <form action="/userRegister">
        <div>请输入账号：<input type="text" id="loginname"/></div>
        <div>请输入密码：<input type="password" id="password"/></div>
        <div>请确定密码：<input type="password" id="pwd"/></div>
        <input type="button" id="register" value="注册"/>
        <!-- <div><input type="button" οnclick="register()"  value="注册"/></div >-->
    </form>
</div>
<script>
    $("#register").click(function () {
        var loginname = document.getElementById('loginname').value;
        if (null == loginname || "" === loginname) {
            alert("请输入用户名");
            return;
        }
        var password = document.getElementById('password').value;
        if (null == password || "" === password) {
            alert("请输入密码");
            return;
        }
        var pwd = document.getElementById('pwd').value;
        if (null == pwd || "" === pwd) {
            alert("请确定密码");
            return;
        }

        $.ajax({
            url: "http://localhost:8080/sel/userRegister",
            type: "POST",
            data: {
                "loginname": loginname,
                "password": password,
                "pwd": pwd,
            },
            dataType: "json",
            success: function (data) {
                //后台返回数据
                if (data.status === "ok") {
                    alert(data.message);   //注册成功
                    window.location.href = "/userLogin";
                } else {
                    alert("注册失败");
                }

            },
            error: function (result) {
                alert("请求错误！", console.result);
            }

        });
    })
</script>
</body>
</html>